Public Class Posting
    Private _db As IDataAccess


    Public Sub New()
        Me._id = Guid.NewGuid.ToString()
        Me._createdAt = DateTime.Now
    End Sub

    Public Sub New(ByVal db As IDataAccess, ByVal parent As Posting)
        Me._db = db
        Me._id = Guid.NewGuid.ToString()
        Me._parent = parent
        Me._createdAt = DateTime.Now
    End Sub

    Public Sub New(ByVal db As IDataAccess, ByVal id As String, ByVal parent As Posting)
        Me._db = db
        Me._id = id
        Me._parent = parent
    End Sub


    Private _id As String
    Public ReadOnly Property Id() As String
        Get
            Return _id
        End Get
    End Property


    Private _parent As Posting
    Public ReadOnly Property Parent() As Posting
        Get
            Return _parent
        End Get
    End Property


    Private _subject As String
    Public Property Subject() As String
        Get
            Return _subject
        End Get
        Set(ByVal value As String)
            _subject = value
        End Set
    End Property


    Private _text As String
    Public Property Text() As String
        Get
            Return _text
        End Get
        Set(ByVal value As String)
            _text = value
        End Set
    End Property


    Private _replies As List(Of Posting)
    Public ReadOnly Property Replies() As List(Of Posting)
        Get
            If Me._replies Is Nothing Then
                Me._replies = New List(Of Posting)(Me._db.FindPostingsByParent(Me))
                Me._replies.Sort(New Comparison(Of Posting)(AddressOf ComparePostingsByCreatedAt))
            End If

            Return Me._replies
        End Get
    End Property

    Private Function ComparePostingsByCreatedAt(ByVal a As Posting, ByVal b As Posting) As Integer
        Return a.CreatedAt.CompareTo(b.CreatedAt)
    End Function


    Private _createdBy As String
    Public Property CreatedBy() As String
        Get
            Return _createdBy
        End Get
        Set(ByVal value As String)
            _createdBy = value
        End Set
    End Property


    Private _createdAt As DateTime
    Public Property CreatedAt() As DateTime
        Get
            Return _createdAt
        End Get
        Set(ByVal value As DateTime)
            _createdAt = value
        End Set
    End Property
End Class